#include <iostream>
#include <cmath>
#include <set>
using namespace std;
const int value = 30020;
int a[value], d[value], v[value], p[value], counts[value];
set<int> b;
int main(){
    freopen("detect3.in", "r", stdin);
    freopen("detect.out", "w", stdout);
    int t;
    int cnt;
    cin >> t;
    for (int i = 0; i < t; i ++){
        int n, m, l, V;
        int cnt = 0;
        cin >> n >> m >> l >> V;
        for (int j = 0; j < n; j ++){
            cin >> d[j] >> v[j] >> a[j];
        }
        for (int j = 0; j < m; j ++){
            cin >> p[j];
            int s = b.size();
            for (int k = 0; k < n; k ++){
                if (d[k] <= p[j]){
                    if (a[k] == 0 && v[k] <= V){
                        b.insert(k);
                    }
                    if (a[k] != 0 && sqrt(v[k] * v[k] + 2 * a[k] * (p[j] - d[k])) > V){
                        b.insert(k);
                    }
                }
            }
            if (b.size() == s){
                cnt ++;
            }
        }
        cout << b.size()  << " " << cnt << endl;
    }
    return 0;
}
